﻿using System;
using NUnit.Framework;
using PropertyExpression.ControllableQuery;
using PropertyExpression.ControllableQuery.Toolkit;

namespace ConsoleApplication3
{
    public class Program
    {
        private static void Main()
        {
            var modelCode = Console.ReadLine();
            var modelSequence = Console.ReadLine();
            foreach (var record in QExecutor.MaterializeReader(
                context => new {
                                   ModelCode = context.Param(modelCode),
                                   ModelSequence = context.Param(modelSequence)
                               },
                p => new Q(@"
SELECT  ModelCode,
        ModelSequence
FROM    Model
WHERE   ModelCode = ")._(p.ModelCode)._(@"
        AND ModelSequence = ")._(p.ModelSequence)
                         .Query(new {
                                        ModelCode = default(string),
                                        ModelSequence = default(string)
                                    })))
            {
            }
        }
    }

    [TestFixture]
    public class QueryTester
    {
        [Test]
        public void AllQueryTest()
        {
            //QueryChecker.CheckAllQueries(
            //    QExecutor.ConnectionString,
            //    typeof (Program).Assembly,
            //    (type, context) => { throw new ApplicationException(); }
            //    );
            QueryChecker.CheckQueries(
                QExecutor.ConnectionString,
                context => new Q("SELECT N'test' AS Test").Query(new {Test = default(string)}));
        }
    }
}